<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/myjs.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css"/>
    <style>
        .form-control{
            width: 200px;
            display: inline-block;
        }
        #result{
            color: gray;
            float: right;
        }
        .showCount{
            color: red;
            font-size: 20px;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div>
    <form id="queryForm">
        籍贯：<input name="grand" id="grand" class="form-control">
        朝代：<input name="dynName" id="dynName" class="form-control">
        姓、名、字：<input name="docName" id="docName" class="form-control">
        著作：<input name="bookName" id="bookName" class="form-control"><br>
        简介：<input name="introduce" id="introduce" class="form-control">
        备注：<input name="memo" id="memo" class="form-control">
        <input type="button" id="btnQuery" class="btn btn-primary" value="查询">
    </form>
    <div id="result">本次查询共<span class="showCount" id="pageCount"></span>页，
        <span class="showCount" id="listCount"></span>条记录
    </div>
</div>
<table class="table table-hover" >
    <tr class="table-active">
        <td>编号</td><td>作者</td><td>书名</td><td>朝代</td><td>省份</td><td>城市</td><td>县</td>
        <td>册数</td><td>出版年份</td><td>简介</td><td>备注</td><td>操作</td>


    </tr>
    <tbody id="tbdoc"></tbody>
</table>
<nav aria-label="Page navigation example">
    <ul class="pagination"></ul>
</nav>
<!--js代码-->
<script>
    $(function () {
        $("#btnQuery").on("click",function () {
            findBook(1,8);
        })
    })
    function findBook(page,size) {
        $.get(
            '/book/findBook',
            $("#queryForm").serialize()+"&page="+page+"&size="+size,
            function (pageInfo) {
                console.log(pageInfo);
                let tb=$("#tbdoc");
                tb.empty();
                let blist=pageInfo.list;
                for(let i in blist){

                    let tr=`<tr>
                                   <td>${blist[i].bookid} </td>
                                   <td>${blist[i].docName} </td>
                                   <td>${blist[i].bookname} </td>
                                   <td>${blist[i].dynName} </td>
                                   <td>${blist[i].provName} </td>
                                   <td>${blist[i].city}</td>
                                   <td>${blist[i].county} </td>
                                   <td>${blist[i].volume} </td>
                                   <td>${blist[i].pubYear} </td>
                                   <td width="300px">${blist[i].introduce} </td>
                                   <td width="300px">${blist[i].memo} </td>
                                    <td><button type="button" onclick="findBookById(${blist[i].bookId})"
                                    class="btn btn-primary" data-toggle="modal" data-target="#docModal">修改</button>
                                    </td>
                                </tr>`;
                    tb.append(tr);
                }
                let liFirst=pageInfo.isFirstPage?"":`<li class="page-item"><a class="page-link" href="javascript:findBook(${page-1},${size})">上一页</a></li>`;

                let li="";
                for(let i in pageInfo.navigatepageNums) {
                    let pn=pageInfo.navigatepageNums[i];
                    li += `<li class="page-item"><a class="page-link" href="javascript:findBook(${pn},${size})">${pn}</a></li>`
                }

                let liLast=pageInfo.isLastPage?"":`<li class="page-item"><a class="page-link" href="javascript:findBook(${page+1},${size})">下一页</a></li>`;
                $(".pagination").empty();
                $(".pagination").append(liFirst+li+liLast);
                $("#pageCount").html(pageInfo.pages);
                $("#listCount").html(pageInfo.total);


            },'json'
        );
    }
    function findBookById(mid){
        $.get(
            '/book/findBookById.do',
            {bookId:mid},
            function (book) {
                console.log(book);
                addFormData("docForm",book);


            },'json'
        );
    }

    function updateBook(){
        $.post(
            '/book/updateBook',
            $("#updateBookForm").serialize(),
            function(num){
                $(".alert").html("医籍信息修改成功！");
                setTimeout(clearAlert,2000);
            },
            'json'
        );
    }
</script>
<!-- Modal -->
<div class="modal fade" id="docModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">医籍修改</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="updateBookForm"  method="post" >
                    <input type="text" name="docId">
                    <table class="table table-hover">
                        <tr>
                            <td>姓名</td>
                            <td> <input type="text" onchange="copyUsername(this.value)"  name="doc_name" class="form-control">
                            </td>
                            <td>电话</td>
                            <td> <input type="text"  name="doc_tel" class="form-control"></td>
                        </tr>
                        <tr>
                            <td>身份证</td>
                            <td> <input type="text"  name="doc_idcard" class="form-control"></td>
                            <td>用户名</td>
                            <td> <input type="text"  name="doc_username" class="form-control"></td>
                        </tr>
                        <tr>
                            <td>入职日期</td>
                            <td> <input type="date"  name="doc_hiredate" class="form-control"></td>
                            <td>部门</td>
                            <td> <select id="fk_dept_id" name="fk_dept_id" class="form-control"></select></td>
                        </tr>
                        <tr>
                            <td rowspan="2">备注</td>
                            <td rowspan="2">
                                <textarea  rows="4" cols="20" name="doc_memo" class="form-control"></textarea>
                            </td>
                            <td >角色</td>
                            <td><select id="fk_role_id" name="fk_role_id" class="form-control"></select></td>
                        </tr>
                    </table>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" onclick="checkIdCard()" class="btn btn-primary" data-dismiss="modal">修改类型</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>